package xyf.p01.array_nodelist;

import commons.ListNode;

/**
 * ClassName: P0876_MiddleNode
 * Description:
 * Author: xyf
 * Date: 9/2/22 10:44 PM
 * Version: 1.0
 **/
public class P0876_MiddleNode
{
    public ListNode middleNode(ListNode head)
    {
        ListNode tmp = head;
        while (head.next != null && head.next.next != null)
        {
            tmp = tmp.next;
            head = head.next.next;
        }
        if (head.next != null)
        {
            return tmp.next;
        }
        else
        {
            return tmp;
        }
    }
}